package com.zy.teacherSecretarySide.controller;

import com.zy.teacherSecretarySide.entity.TeacherSecretary;
import com.zy.teacherSecretarySide.service.ITeacherSecretaryService;
import com.zy.util.R;
import com.zy.util.RandomNum;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


/**
 * @author 29787
 */
@RestController
public class SecretaryController {

    @Autowired
    private ITeacherSecretaryService itss;

    /**
     * 教学秘书端登陆接口
     * @param teacherSecretary
     * @return R
     */
    @PostMapping
    @RequestMapping(value = "/secretaryLogin")
    public R secretaryLogin (@RequestBody  TeacherSecretary teacherSecretary){
        TeacherSecretary ts=itss.teacherSecretaryLogin(teacherSecretary.getSecretaryNum(),teacherSecretary.getSecretaryPassword());
        return new R(ts==null ? false :true,ts);
    }

    /**
     * 教学秘书注册接口
     * @param teacherSecretary
     * return R
     */
    @PostMapping
    @RequestMapping(value = "/secretaryRegister")
    public R secretaryRegister (@RequestBody TeacherSecretary teacherSecretary){
        if(itss.getSecretaryById(teacherSecretary.getSecretaryNum()) != null){
            return new R(false,"err");
        }else{
            Integer id = RandomNum.getRandomID(6);
            teacherSecretary.setSecretaryId(id);
            teacherSecretary.setSecretaryShiro(4);
            return new R(itss.save(teacherSecretary),teacherSecretary);
        }
    }
}
